package top.tagao.study03_Map;

import java.io.*;
import java.util.Iterator;
import java.util.Properties;

/**
 * @author fu-xiao-liu
 * @Date 2022/4/16 23:09
 */

public class study_06_Properties {
    public static void main(String[] args) throws IOException {
        Properties prop = new Properties();
        // 1.读取属性文件jdbc.properties
        InputStream in = study_06_Properties.class.getClassLoader().getResourceAsStream("jdbc.properties");
        // 2. 加载属性列表
        prop.load(in);
        Iterator<String> it=prop.stringPropertyNames().iterator();
        while(it.hasNext()){
            String key=it.next();
            System.out.print(key+":"+prop.getProperty(key) + " ");
        }
        in.close();

        // 1.保存属性到jdbc.properties文件  true表示追加打开
        FileOutputStream out = new FileOutputStream("study-08-javaConllection/src/main/resources/jdbc.properties", true);
        prop.setProperty("phone", "10086");
        prop.store(out, "The New properties file");
        out.close();
    }
}